home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / RC Missile.lua < prev    next >
Text File  |  2010-09-22  |  7KB  |  193 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon RC Missile Launcher + Projectile Missile
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, August 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.rcmissile={}
  10. cc.rcmissile.missile={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.rcmissile.gfx_wpn=loadgfx("weapons/launcher.bmp")                    -- Weapon Image
  14. setmidhandle(cc.rcmissile.gfx_wpn)
  15. cc.rcmissile.gfx_pro=loadgfx("weapons/rcmissile.bmp")                    -- Projectile Image
  16. setmidhandle(cc.rcmissile.gfx_pro)
  17. cc.rcmissile.sfx_attack=loadsfx("rocketrelease.wav")                    -- Attack Sound
  18. cc.rcmissile.sfx_homing=loadsfx("homing.wav")                            -- Homing Sound
  19.  
  20. --------------------------------------------------------------------------------
  21. -- Weapon: RC Missile Launcher
  22. --------------------------------------------------------------------------------
  23.  
  24. cc.rcmissile.id=addweapon("cc.rcmissile","RC Missile",cc.rcmissile.gfx_pro,1,2)    -- Add Weapon (1 use, first in round 2)
  25.  
  26. function cc.rcmissile.draw()                                            -- Draw
  27.     setblend(blend_alpha)
  28.     setalpha(1)
  29.     setcolor(255,180,120)
  30.     drawinhand(cc.rcmissile.gfx_wpn,6,0)
  31.     -- HUD chargebar
  32.     if weapon_charge>0 and weapon_shots==0 then
  33.         hudchargebar(weapon_charge,100)
  34.     end
  35.     -- HUD Crosshair
  36.     if weapon_shots==0 then
  37.         hudcrosshair(6,3)
  38.     end
  39. end
  40.  
  41. function cc.rcmissile.attack(attack)                                    -- Attack
  42.     if (weapon_shots<=0) then
  43.         -- Charge
  44.         if (attack==1) then
  45.             weapon_charge=weapon_charge+1                            -- Increase charge
  46.         end
  47.         -- Fire a projectile (on release/full charge)
  48.         if (attack==0 and weapon_charge>0) or (weapon_charge>=100) then
  49.             -- No more weapon switching!
  50.             useweapon(0)
  51.             -- Disable player control
  52.             playercontrol(0)
  53.             -- Make sure that there is enough round time
  54.             secondsleft=math.floor(getframesleft()/50)
  55.             changeturntime(15-secondsleft)
  56.             -- SFX
  57.             playsound(cc.rcmissile.sfx_attack)
  58.             -- Launch
  59.             weapon_shots=weapon_shots+1
  60.             id=createprojectile(cc.rcmissile.missile.id)
  61.             projectiles[id]={}
  62.             -- Ignore collision with current player at beginning
  63.             projectiles[id].ignore=playercurrent()
  64.             -- Set initial position of projectile
  65.             projectiles[id].x=getplayerx(0)+(6*getplayerdirection(0))+math.sin(math.rad(getplayerrotation(0)))*10.0
  66.             projectiles[id].y=getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*10.0
  67.             -- Set timer
  68.             projectiles[id].timer=15*50
  69.             -- Initial movement
  70.             projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*20
  71.             projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*20
  72.             projectiles[id].x=projectiles[id].x-projectiles[id].sx
  73.             projectiles[id].y=projectiles[id].y-projectiles[id].sy
  74.             cc.rcmissile.missile.move(id,0)
  75.             -- Set speed of projectile
  76.             projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*(weapon_charge/100.0)*10.0
  77.             projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*(weapon_charge/100.0)*10.0
  78.             -- Effects
  79.             recoil(2)
  80.         end
  81.     end
  82. end
  83.  
  84. --------------------------------------------------------------------------------
  85. -- Projectile: Missile
  86. --------------------------------------------------------------------------------
  87.  
  88. cc.rcmissile.missile.id=addprojectile("cc.rcmissile.missile")        -- Add Projectile
  89.  
  90. function cc.rcmissile.missile.draw(id)                                -- Draw
  91.     -- Setup draw mode
  92.     setblend(blend_alpha)
  93.     setalpha(1)
  94.     setcolor(255,255,255)
  95.     setscale(1,1)
  96.     -- Calculate projectile rotation
  97.     setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
  98.     -- Draw projectile
  99.     drawimage(cc.rcmissile.gfx_pro,projectiles[id].x,projectiles[id].y)
  100.     -- Draw Arrow if out of Screen
  101.     outofscreenarrow(projectiles[id].x,projectiles[id].y)
  102. end
  103.  
  104. function cc.rcmissile.missile.update(id)                            -- Update
  105.     cc.rcmissile.missile.move(id,1)
  106. end
  107.  
  108. function cc.rcmissile.missile.move(id,fx)
  109.     -- Control by player
  110.     if projectiles[id].timer==(14*50) then
  111.         -- Start Control FX
  112.         playsound(cc.rcmissile.sfx_homing)
  113.         particle(p_ring,projectiles[id].x,projectiles[id].y)
  114.         particlecolor(255,150,0)
  115.     end
  116.     if projectiles[id].timer<=(14*50) then
  117.         rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  118.         --speed=math.sqrt(math.pow(projectiles[id].sx,2)+math.pow(projectiles[id].sy,2))
  119.         if keydown(key_left)==1 then
  120.             rot=rot-3
  121.         elseif keydown(key_right)==1 then
  122.             rot=rot+3
  123.         end
  124.         projectiles[id].sx=math.sin(math.rad(rot))*6.0
  125.         projectiles[id].sy=-math.cos(math.rad(rot))*6.0
  126.     else
  127.         rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  128.     end
  129.     -- Particle Tail
  130.     if (fx==1) then
  131.         particle(p_smoke,projectiles[id].x-math.sin(math.rad(rot))*7,projectiles[id].y+math.cos(math.rad(rot))*7)
  132.         particlespeed(math.random(-2,2)*0.1,math.random(-2,2)*0.1)
  133.         particlefadealpha(0.01)
  134.         if projectiles[id].timer<=(14*50) then
  135.             particle(p_lightpuff,projectiles[id].x-math.sin(math.rad(rot))*6,projectiles[id].y+math.cos(math.rad(rot))*6)
  136.             particlefadealpha(0.04)
  137.         end
  138.     end
  139.     -- Wind + Gravity influence on speed
  140.     projectiles[id].sx=projectiles[id].sx+getwind()
  141.     projectiles[id].sy=projectiles[id].sy+getgravity()
  142.     -- Move (in substep loop for optimal collision precision)
  143.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
  144.     msubx=projectiles[id].sx/msubt
  145.     msuby=projectiles[id].sy/msubt
  146.     for i=1,msubt,1 do
  147.         projectiles[id].x=projectiles[id].x+msubx
  148.         projectiles[id].y=projectiles[id].y+msuby
  149.         -- Collision
  150.         if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*3,projectiles[id].y-math.cos(math.rad(rot))*3)==1 then
  151.             if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
  152.                 projectiles[id].timer=0
  153.                 break
  154.             end
  155.         else
  156.             projectiles[id].ignore=0
  157.         end
  158.         -- Water
  159.         if (projectiles[id].y)>getwatery() then
  160.             -- Effects
  161.             particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  162.             playsound(sfx_hitwater1)
  163.             -- Free projectile
  164.             freeprojectile(id)
  165.             -- End Turn
  166.             endturn()
  167.             break
  168.         end
  169.     end
  170.     -- Timer / Explode
  171.     if (fx==1) then
  172.         projectiles[id].timer=projectiles[id].timer-1
  173.     end
  174.     if projectiles[id].timer<=0 then
  175.         -- Cause damage
  176.         arealdamage(projectiles[id].x,projectiles[id].y,120,60)
  177.         -- Destroy terrain
  178.         terrainexplosion(projectiles[id].x,projectiles[id].y,35,1)
  179.         -- Crater
  180.         grey=math.random(0,40)
  181.         if math.random(0,1)==1 then
  182.             terrainalphaimage(gfx_crater125,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
  183.         else
  184.             terrainalphaimage(gfx_crater150,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
  185.         end
  186.         -- Free projectile
  187.         freeprojectile(id)
  188.         -- End Turn
  189.         endturn()
  190.     end
  191.     -- Scroll to projectile
  192.     scroll(projectiles[id].x,projectiles[id].y)
  193. end